import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D 
from matplotlib import cm
from sklearn.linear_model import LogisticRegression
from sklearn.datasets import make_blobs
import numpy as np
  
X,y = make_blobs(n_samples=200,n_features=3,centers=2,random_state=9,
                 cluster_std = 0.9)

logistic_regression = LogisticRegression(C=2,solver='liblinear')
lr = logistic_regression.fit(X,y)

X_h = np.arange(int(min(X[:,0])), int(max(X[:,0])), 0.001)
Y_h = np.arange(int(min(X[:,1])), int(max(X[:,1])), 0.001)
X_h, Y_h = np.meshgrid(X_h, Y_h)
Z = -(lr.coef_[0][0]*X_h+lr.coef_[0][1]*Y_h+lr.intercept_)/lr.coef_[0][2]

fig = plt.figure(figsize=(7, 5))
ax = Axes3D(fig, elev=50, azim=-20)
# Plot the features
ax.scatter(X[:,0], X[:,1], y, c='b', marker='o')
# Plot the plane surface.
ax.plot_surface(X_h, Y_h, Z, cmap=cm.coolwarm)       
plt.show()
